// import axios from 'axios'

const axios = require('axios');

axios({
  // url: 'http://httpbin.org/get'
  url: 'http://123.207.32.32:8000/home/multidata',
  methods: 'get' // 默认是GET请求
})//.then(console.log);

// http://123.207.32.32:8000/home/data?type=pop&page=1
// http://152.136.185.210:7878/api/m5/home/data?type=pop&page=1
axios.get('http://152.136.185.210:7878/api/m5/home/data', {
  params: {
    type: 'sell',
    page: 1
  }
})// .then(console.log);

/**
 * axios 发送并发请求
 **/
axios.all([axios({
  url: 'http://152.136.185.210:7878/api/m5/home/multidata'
}), axios({
  url: 'http://152.136.185.210:7878/api/m5/home/data',
  params: {
    type: 'sell',
    page: 5
  }
})])
// .then(results => {
//   for (const result of results) {
//     console.log(result.data);
//   }
// });
.then(axios.spread((result1, result2) => {
  // console.log("result1 = ", result1);
  // console.log("result2 = ", result2);
}));

/**
 * axios 全局配置
 */
// axios.defaults.baseURL = 'http://152.136.185.210:7878/api/m5';
// axios.defaults.timeout = 5000;


// axios.get('/home/multidata').then(console.log);


// 创建axios示例
const instance = axios.create({
  // 当前示例的配置
  baseURL: 'http://152.136.185.210:7878/api/m5',
  timeout: 1000
});

// instance.get('/home/multidata').then(res => console.log('result = ', res.data), err => console.warn(err));

const requests = require('./network/requests');
// requests.request({
//   url: '/home/multidata'
// }, res => console.log('test requests = ', res.data));

requests.request({url: '/home/multidata'}).then(console.log).catch(console.warn);